import axios, { AxiosRequestConfig } from 'axios'

const http = axios.create()

http.interceptors.request.use(
  function (config: any) {
    return config
  },
  function (error) {
    return Promise.reject(error)
  }
)
http.interceptors.response.use(
  (response) => {
    // 响应成功
    if (response.status === 200) {
      return response.data
    }

    return Promise.reject(new Error(response.data.msg || 'Error'))
  },
  (error) => {
    return Promise.reject(new Error(error.name || '接口错误'))
  }
)
export default http
